/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.scs.ubbcluj.view;

import edu.scs.ubbcluj.model.Attribute;
import edu.scs.ubbcluj.model.Database;
import edu.scs.ubbcluj.model.ForeignKey;
import edu.scs.ubbcluj.model.Table;
import java.util.List;

/**
 *
 * @author Torok
 */
public class Util {
    
    public static Attribute getAttributeByName(Table t,String name){
        for (Attribute attr:t.getPrimaryKeys()){
            if (attr.getName().equals(name))
                return attr;
        }
        for (Attribute attr:t.getAttributes()){
            if (attr.getName().equals(name))
                return attr;
        }
        for (Attribute attr:t.getForeignKeys()){
            if (attr.getName().equals(name))
                return (Attribute)attr;
        }
        return null;
    }
    
    public static Attribute getAttributeByName(List<Attribute> attrs,String name){
        for (Attribute attr:attrs){
            if (attr.getName().equals(name))
                return attr;
        }
        return null;
    }
    
    public static ForeignKey getForeignKeyByName(List<ForeignKey> attrs,String name){
        for (ForeignKey attr:attrs){
            if (attr.getName().equals(name))
                return attr;
        }
        return null;
    }
    
    public static Table getTableByName(List<Table> tables,String name){
        for (Table table:tables){
            if (table.getName().equals(name))
                return table;
        }
        return null;
    }
    public static Database getDBByName(List<Database> databases,String name){
        for (Database db : databases) {
            if (db.getName().equals(name))
                return db;
        }
        return null;
    }
}
